/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rom.script;

import java.io.Serializable;
import java.util.ArrayList;

/**
 *
 * @author Luis
 */
public class Bonus implements Serializable {

    private String bonus;
    private ArrayList<Variable> vars = new ArrayList<>();

    public void set() {
        for (Variable v : vars) {
            bonus = bonus.replace(v.getName(), v.getValue().toString());
        }
    }

    public void setBonus(String bonus) {
        this.bonus = bonus;
    }

    public void setVar(Variable var) {
        if (!vars.contains(var)) {
            vars.add(var);
        }
    }

    public void deleteVar(Variable var) {
        if (vars.contains(var)) {
            vars.remove(var);
        }
    }

    public Variable getVar(int index) {
        if (vars.size() >= index) {
            return vars.get(index);
        }
        return null;
    }

    public String get() {
        return this.bonus;
    }

    public int size() {
        return vars.size();
    }

    @Override
    public String toString() {
        return bonus;
    }
}
